<%@ include file="/en/jsp/static.jsp" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>

<%
  int SYSTEMCAT = Integer.parseInt((String)request.getAttribute("SYSTEMCAT"));
  //XTODO: check user rights
%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>
<table width="100%" border=0 cellpadding=0 cellspacing=0>
<tr><td>
<script LANGUAGE="JavaScript">
function onAdd()
{
  var choice = document.theForm.CHOICE.value;
  if ( choice != null && choice.length > 0 )
  {
    var option = new Option(choice, choice);
    document.theForm.CATEGORIES.options[document.theForm.CATEGORIES.length] = option;
  }
}

function onRemove()
{
  var options = document.theForm.CATEGORIES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      if (options[i].selected == true)
        options[i] = null;
    }
  }
//	document.theForm.CATEGORIES.focus();
}

//select all the items so they will be sent out
function onSubmit()
{
//	alert("Set selected");
  var options = document.theForm.CATEGORIES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      options[i].selected = true;
    }
//		alert("Set selected");
  }
}
</script>

  <table width="100%" height=26 align=middle border=0 cellpadding=4 cellspacing=0 bgcolor=#6c005f style="font-size:16px;color:#e0e0e0">
    <tr><td> <img src="<%=BoxStatic.imageDir%>smallnews.gif" width=16 height=15 border=0 align=top>
      <b>Box Tasks Category Edit</b>
    </td></tr>
  </table>
  <br>
  <form action="<%=BoxStatic.servletDir%>BoxTodoCatAction" method=get name=theForm >
  <table width= "100%" border=1 cellspacing=0 cellpadding=1>
          <tr><td>
            <input type=text name="CHOICE" size=40 maxlength=200>
            <input type="button" value="Add Category" name="Add" onclick="onAdd()">
          </td></tr>
          <tr><td>
          Current categories:   <input type="button" value="Remove Selected Choices" name="Remove" onclick="onRemove()">
          </td></tr>
          <tr><td>
            <select name="CATEGORIES" size="5" multiple>

<%
  linuxbox.todo.logic.BoxTodoCat home = new linuxbox.todo.logic.BoxTodoCat();
  String[] cats = null;
  if (SYSTEMCAT == 0)
  {
    cats = home.getUserCategories(curUserID);
  }
  else
    cats = home.getSystemCategories();
  out.print(cats);
  out.print("size:"+cats.length);
  out.print("SYSTEMCAT:"+SYSTEMCAT);
  out.print("curUserID:"+curUserID);
  if (cats!=null && cats.length >0)
  {
    for(int i=0; i< cats.length; i++)
    {
      out.print("<option value="+cats[i]+">"+cats[i]+"</option>");
    }
  }
%>
      </select>
    </td></tr>
    <tr><td>
            <input type=submit value="Save" onclick="onSubmit()" name=
            <%
              if (SYSTEMCAT == 0)
                out.print("SubmitSave");
              else
                out.print("SubmitSysSave");
            %>
            >
            <input type=button value="Cancel" onclick="window.history.go(-1)" >
          </td></tr>
    </td></tr>
  </table>
  </form>
  <hr width="100%" color=#6c005f align=left>

</td></tr>
</table>
<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
